<template>
		<z-paging ref="paging" v-model="dataList" :auto="false" @query="queryList"
		:default-page-size="100"
		loading-more-no-more-text="已经到底线了">
		   <view class="box">
		       <image class="img"
		       :src="item.thumbnail||item.cover" 
			   mode="aspectFill"
		       :style="{'height': item.img_new_H + 'px'}"
		        v-for="(item, index) in dataList" :key="index" 
				@longpress="longpress(item)"></image>
			</view>
		 </z-paging>
</template>

<script>
	import interfaces from "@/utils/interfaces.js"
	import config from "@/utils/config.js"
	import tools from '@/utils/tools.js'
	export default {
		components: {
		},
		data() {
			return {
				dataList:[]
			}
		},
		methods: {
			queryList(pageNum, pageSize) {				
				let self = this
				self.request({
					url:interfaces.wallpaper_list,
					methods:"GET",
					success:(res)=> {
						//console.log("获取壁纸数据:" + res)
						if(pageNum == 1) {
							setTimeout(function() {
								uni.showToast({
									icon:"none",
									title:"长按图片可保存到相册",
									duration:2000,
								})
							}, 500);
							self.dataList = []
						}
						let lists = res.content
						self.$refs.paging.complete(lists)
						self.firstLoaded = true
						
						let imgWidth = uni.getWindowInfo().windowWidth
						lists.forEach((item, index) =>{
							let img_bili = item.img_w / item.img_h
							let img_newH = imgWidth / img_bili
							self.$set(item, "img_new_H", img_newH)
						})
						self.dataList.concat(lists)
						
					},
					fail:(error)=> {
						console.log("错误 错误 错误:" + error + ":" + url)
					}
				})			
			},
			longpress(item) {
				uni.showActionSheet({
					itemList:['保存图片'],
					success: (res) => {
						if(res.tapIndex === 0) {
							tools.saveImageToAlbum(item.cover)
						}
					}
				})
			}
		},
		mounted() {
			this.$refs.paging.reload();
		}
	}
</script>

<style lang="scss">
	.box {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
		justify-content: center;
		padding: 12px;
		
		.img {
			display: flex;
			width: 100%;
			height: 200rpx;
			margin: 8px 0px;
			border-radius: 20px;
			border: 3px solid #D98A47;
			box-sizing: border-box;
			background-color: #ffffff;
		}
	}
	
</style>
